﻿#include "stdafx.h"

#include "Record.h"
#include "UiHelpers.h"

//======================================================================================================================
void fillRecords( QComboBox * Widget , QRecord & dsRecords , short iName , short iData )
{
	Widget->clear( );
	int numRecords = dsRecords.rowCount( );
	for( int Row = 0 ; Row < numRecords ; Row ++ )
	{
		QString Name = dsRecords.data( Row , iName ).toString( );
		QVariant Data = dsRecords.data( Row , iData );
		Widget->insertItem( Row , Name , Data );
	}
}

bool fillRecords( QComboBox * Widget , QString SQL , const QVariant & Value )
{
	QRecord dsRecords;
	QString Error;
	int Caller = dsRecords.select( SQL);
	CHK_EXP_RET(!Caller, false);
	fillRecords( Widget , dsRecords , 0 , 1 );
	return findData( Widget , Value );
}

//======================================================================================================================
int findData( QComboBox * Widget , const QVariant & Data )
{
	int index = Widget->findData( Data );
	Widget->setCurrentIndex( index );
	return index;
}

int findText( QComboBox * Widget , const QString & Text )
{
	int index = Widget->findText( Text );
	Widget->setCurrentIndex( index );
	return index;
}

//===================================================================================================================================
bool findString(QString strSepartor, QString strSep, QString strSource)
{
	QStringList listSepartor = strSepartor.split(strSep);
	for (int i = 0; i < listSepartor.count(); i++)
	{
		if (listSepartor[i] == strSource)
		{
			return true;
		}
	}
	return false;
}
